﻿using MediatR;
using ProductionManagement.Application.Command.SendWorkersForQualityInspectionCommand;
using ProductionManagement.Domain.Dtos.SendWorkersForQualityInspectionDTOS;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.SendWorkersForQualityInspectionCommandHandlers
{
    public class SendWorkersForQualityInspectionSetCommandHandlers : IRequestHandler<SendWorkersForQualityInspectionSetCommand, SendWorkersForQualityInspectionSetDtos>
    {
        protected readonly ISendWorkersForQualityInspectionRepository repository;

        public SendWorkersForQualityInspectionSetCommandHandlers(ISendWorkersForQualityInspectionRepository repository)
        {
            this.repository = repository;
        }

        public async Task<SendWorkersForQualityInspectionSetDtos> Handle(SendWorkersForQualityInspectionSetCommand request, CancellationToken cancellationToken)
        {
            var list = (await repository.GetAll()).First(x => x.SendWorkersForQualityInspectionId == request.id);
            SendWorkersForQualityInspectionSetDtos newlist = new SendWorkersForQualityInspectionSetDtos()
            {
                SendWorkersForQualityInspectionId = list.SendWorkersForQualityInspectionId,
                AddName = list.AddName,
                AddTime = list.AddTime,
                Cause = list.Cause,
                DelName = list.DelName,
                DelTime = list.DelTime,
                IsDel = list.IsDel,
                NumberOfRework = list.NumberOfRework,
                Office_Id = list.Office_Id,
                PersonnelTime = list.PersonnelTime,
                PName = list.PName,
                PNumber = list.PNumber,
                PSpec = list.PSpec,
                QualifiedQuantity = list.QualifiedQuantity,
                QualityInspectionResults = list.QualityInspectionResults,
                Rate = list.Rate,
                ScrappedQuantity = list.ScrappedQuantity,
                SWFIDate = list.SWFIDate,
                SWFIPeople = list.SWFIPeople,
                SWFIPersonnel = list.SWFIPersonnel,
                SWFISource = list.SWFISource,
                SWFQICode = list.SWFQICode,
                TheNumberOfSubmissions = list.TheNumberOfSubmissions,
                TypeOfQC = list.TypeOfQC,
                User_Id = list.User_Id
            };
            return newlist;
        }
    }
}
